<template>
  <div>
    <!-- {{ verifykey }} -->
  </div>
</template>
<script>
import { bus } from '@/main.js';

import { mapState, mapMutations } from 'vuex';

export default {
  name: 'init',
  // 项目初始化组件，基本只在app.vue中引入
  // 只调用mounted做初始化动作
  // 请求后数据进入vuex/store中缓存，前后loading遮罩提示加载过程
  mixins: [], //混入
  components: {}, //组件
  props: {}, //集成属性
  data() {
    return {
      loading: null,
      verifykey: '',
    };
  },
  computed: {
    ...mapState([]),
  },
  methods: {
    ...mapMutations([]),
    openLoading: function(text) {
      this.loading = this.$loading({
        lock: true,
        background: 'rgba(255,255,255,0.6)',
        text: _.isString(text) ? text : '',
      });
    },
    closeLoading: function() {
      this.loading.close();
    },
    getUrlArgs: function() {
      let wl = window.location;
      let search = wl.search == '' ? wl.hash.split('?')[1] : wl.search;
      return this.$qs.parse(search, {
        ignoreQueryPrefix: true,
      });
    },
    initVerifykey: function() {
      let today = this.$moment().format('YYYYMMDD');
      let verifykey = this.MD5(today).toUpperCase();
      this.verifykey = verifykey;
      return Promise.resolve(verifykey);
    },
  },
  mounted: function() {
    this.openLoading('项目初始化中...');
    this.initVerifykey()
      .then((res) => {
        let search = this.getUrlArgs();
      })
      .then((res) => {
        this.closeLoading();
      })
      .catch((err) => {
        console.error(err);
      })
      .finally((_) => {});
  }, //在实例挂载到DOM节点上之后
};
</script>
<style lang="less" scoped></style>
